package cn.itcast.job;

import cn.itcast.domain.cargo.Export;
import cn.itcast.service.cargo.ExportService;
import cn.itcast.vo.ExportResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.cxf.jaxrs.client.WebClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("exportJob")
public class ExportJob {


    @Reference
    private ExportService exportService;


    public void queryExportFromHaiguan(){
        System.out.println("定时任务执行了");
//        查询报运到海关但是没有返回结果的报运单
       List<Export> exportList  =  exportService.findByState(5L);
        for (Export export : exportList) {
            ExportResult exportResult = null;
            try {
//                如果没有异常就说明是能正常获取结果了
                exportResult = WebClient.create("http://localhost:9090/ws/export/ep/" + export.getId()).get(ExportResult.class);
                exportService.updateE(exportResult);
            } catch (Exception e) {
                System.out.println(export.getId()+"还没有结果");
            }

        }


    }


}
